﻿using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using ScrumFactory.Login.ViewModel;
using ScrumFactory.Composition.View;




namespace ScrumFactory.Login {

    
    /// <summary>
    /// Interaction logic for LoginDialog.xaml
    /// </summary>            
    [Export(typeof(LoginDialog))]
    public partial class LoginDialog : UserControl, IView {

        public LoginDialog() {
            InitializeComponent();        
        }
        
        private object model;

        /// <summary>
        /// Gets the model.
        /// </summary>
        /// <value>The model.</value>     
        [Import(typeof(LoginViewModel))]
        public object Model {
            get {
                return this.model;
            }
            set {
                this.model = value;
                this.DataContext = value;
            }
        }

        

        /// <summary>
        /// Handles the PasswordChanged event of the PasswordBox control.
        /// Once, Password is not a DP for security reasons, it need to be
        /// done here.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) {
            PasswordBox p = sender as PasswordBox;
            if (p == null)
                return;
            ((LoginViewModel)Model).Password = p.Password;
        }


        public void ResetPassword() {
            passwordTextBox.Clear();
            ((LoginViewModel)Model).Password = passwordTextBox.Password;
        }

        public void InitPassword(string pass) {
            passwordTextBox.Password = pass;
        }

    }
}
